package com.frogs.ucenter.v1.service.platform.caibei;

import java.util.Date;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSONObject;
import com.frogs.system.util.ApplicablePlatformEnum;
import com.frogs.ucenter.entity.UserAccountInfo;
import com.frogs.ucenter.v1.service.PlatformOperationService;
import com.frogs.ucenter.v1.service.platform.base.PlatformBaseOperationService;
import com.frogs.ucenter.v1.util.ApiConstants;

/**
 * 彩贝业务逻辑处理类
 *
 * @author lijian
 * @version 2014年12月9日 - 上午9:32:57
 */
@Service(ApiConstants.VERSION+"caibeiOperationService")
public class CaibeiOperationServiceImpl extends PlatformBaseOperationService implements PlatformOperationService {

	private static final Logger log = LoggerFactory.getLogger(CaibeiOperationServiceImpl.class);

	@Override
	public JSONObject getOpenId(JSONObject object) {
		JSONObject result = new JSONObject();
		String openId = object.getString(ApiConstants.OPEN_ID);
		Date date = new Date();
		result.put(ApiConstants.OPEN_ID, openId);
		result.put(ApiConstants.ACCESS_TOKEN, "");
		result.put(ApiConstants.REFRESH_TOKEN, "");
		result.put(ApiConstants.EXPIRES_DATE, date);
		result.put(ApiConstants.RESULT_CODE, ApiConstants.RESULT_SUCCESS);
		return result;
	}

	@Override
	public JSONObject getAccessTokenByRefreshToken(JSONObject object) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public JSONObject getNickName(JSONObject object) {
		JSONObject result = new JSONObject();
		result.put(ApiConstants.RESULT_CODE, ApiConstants.RESULT_SUCCESS);
		return result;
	}

	@Override
	public JSONObject register(JSONObject object) {
		String nickName = object.getString(ApiConstants.NICK_NAME);
		String expandCode = object.getString(ApiConstants.EXPAND_CODE) == null ? "" : object.getString(ApiConstants.EXPAND_CODE);
		String accountName = this.createAccountName();
		UserAccountInfo userAccountInfo = this.insertUser(accountName, "", "", ApplicablePlatformEnum.WEB.getId(), expandCode, "");
		this.initializeOther(userAccountInfo, nickName);
		object.put("userAccountInfo", userAccountInfo);
		return object;
	}

}
